package com.umgsai.thread.thread34;

import java.util.ArrayList;
import java.util.List;

public class MyStack {
	private List list = new ArrayList();
	synchronized public void push(){
		try {
			while (list.size() == 1) {
				this.wait();//等待消费者通知
			}
			list.add("anyString=" + Math.random());
			this.notifyAll();//通知消费者消费
			System.out.println("push=" + list.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	synchronized public String pop(){
		String returnValue = "";
		try {
			while (list.size() == 0) {
				System.out.println("pop操作中的：" + Thread.currentThread().getName() + " 线程呈wait状态");
				this.wait();//等待生产者通知
			}
			returnValue = "" + list.get(0);
			list.remove(0);
			this.notifyAll();//通知生产者生产
			System.out.println("popo=" + list.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return returnValue;
	}
}
